#ifndef _RGB_H_
#define _RGB_H_

#include <stdio.h>
#include <sys/mman.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>

#define MAP_SIZE 4096UL
#define MAP_MASK (MAP_SIZE-1)
//PWM控制器基地址
#define PWM_ENABLE_REG                  "0x2807e020"
//使能PWM控制器
#define PWM_ENABLE_VAL                  "0xff"
//PWM0引脚的基地址
#define GPIO_PAD_MOOE_PWM0_CHANNEL0_REG "0x32b30050"
//PWM2引脚的基地址
#define GPIO_PAD_MOOE_PWM2_CHANNEL0_REG "0x32b30060"
//用于配置PWM0的相关属性
#define GPIO_PAD_MOOE_PWM0_CHANNEL0_VAL "0x141"
//用于配置PWM2的相关属性
#define GPIO_PAD_MOOE_PWM2_CHANNEL0_VAL "0x141"
#define PWM0_CONTROLLER 				"0"
#define PWM0_CHANNEL0					"0"
#define PWM2_CONTROLLER 				"2"
#define PWM2_CHANNEL0					"2"
//半字2字节
#define WRITE_TYPE_H					"H"
//字4字节
#define WRITE_TYPE_W					"W"
//1字节
#define WRITE_TYPE_B					"B"
//周期
#define PWM_PERIOD						"5000000" 
//占空比
#define PWM_DUTY1						"0"
#define PWM_DUTY2						"5000000"

enum PWMX {
	PWM0,
	PWM2,
	PWM0_PWM2,
	PWMAX
};
extern unsigned long duty1;//0
extern unsigned long duty2;//1000000
extern unsigned long duty;//0
extern int increase;
extern int step;
extern char dutys[256];
extern char pwm0_path[128];
extern char pwm2_path[128];

//使能PWM控制器
extern int PWM_gpio_mode (char *addr, char *type, char *data);
//配置pwm下的节点文件的属性文件,会被set_pwm_value()调用
extern int pwm_config (const char *attr, const char *val, int node);
//将pwm0和pwm2的节点文件导出到用户空间
//注意这个函数应当在pwm_config()和set_pwm_value()前调用!!!!!
extern void set_pwm_export (void);
//配置pwm period,duty_cycle,enable
extern void set_pwm_value (void);
//灯光初始化(关闭灯光)
extern void rgb_init (void);
//红蓝闪烁模式
extern void red_blue_mode (void);
//呼吸灯模式
extern void breath_mode (void);

#endif 
